package fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.example.administrator.weipiao.R;

import java.util.List;

import adapter.MovieAdapter;
import bean.Movies;
import loadresource.Constants;
import loadresource.LoadJsonTask;

/**
 * A simple {@link Fragment} subclass.
 */
public class PerformFragment extends Fragment implements LoadJsonTask.OnGetJsonResultListener{


    private MovieAdapter mAdapter;

    public PerformFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_perform, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ListView mLv = (ListView) view.findViewById(R.id.lv_perform);
        //执行下载Json的异步任务
        new LoadJsonTask(this).execute(Constants.PAHT2);
        mAdapter = new MovieAdapter(view.getContext());
        mLv.setAdapter(mAdapter);
    }

    @Override
    public void onGetJsonResult(List<Movies> result) {
        mAdapter.setData(result);
    }
}
